<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Building applications: GTK+ 3 Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="GTK+ 3 Reference Manual">
<link rel="up" href="gtk-getting-started.html" title="Getting Started with GTK+">
<link rel="prev" href="ch01s03.html" title="Building user interfaces">
<link rel="next" href="ch01s05.html" title="Custom Drawing">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="gtk-getting-started.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="ch01s03.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="ch01s05.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="id-1.2.3.12"></a>Building applications</h2></div></div></div>
<p>An application consists of a number of files:
    </p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">The binary</span></p></td>
<td>This gets installed in <code class="filename">/usr/bin</code>.</td>
</tr>
<tr>
<td><p><span class="term">A desktop file</span></p></td>
<td>The desktop file provides important information about the application to the desktop shell, such as its name, icon, D-Bus name, commandline to launch it, etc. It is installed in <code class="filename">/usr/share/applications</code>.</td>
</tr>
<tr>
<td><p><span class="term">An icon</span></p></td>
<td>The icon gets installed in <code class="filename">/usr/share/icons/hicolor/48x48/apps</code>, where it will be found regardless of the current theme.</td>
</tr>
<tr>
<td><p><span class="term">A settings schema</span></p></td>
<td>If the application uses GSettings, it will install its schema
          in <code class="filename">/usr/share/glib-2.0/schemas</code>, so that tools
          like dconf-editor can find it.</td>
</tr>
<tr>
<td><p><span class="term">Other resources</span></p></td>
<td>Other files, such as GtkBuilder ui files, are best loaded from
          resources stored in the application binary itself. This eliminates the
          need for most of the files that would traditionally be installed in
          an application-specific location in <code class="filename">/usr/share</code>.</td>
</tr>
</tbody>
</table></div>
<p>
    </p>
<p>GTK+ includes application support that is built on top of
    <span class="type">GApplication</span>. In this tutorial we'll build a simple application by
    starting from scratch, adding more and more pieces over time. Along
    the way, we'll learn about <a class="link" href="GtkApplication.html" title="GtkApplication"><span class="type">GtkApplication</span></a>, templates, resources,
    application menus, settings, <a class="link" href="GtkHeaderBar.html" title="GtkHeaderBar"><span class="type">GtkHeaderBar</span></a>, <a class="link" href="GtkStack.html" title="GtkStack"><span class="type">GtkStack</span></a>, <a class="link" href="GtkSearchBar.html" title="GtkSearchBar"><span class="type">GtkSearchBar</span></a>,
    <a class="link" href="GtkListBox.html" title="GtkListBox"><span class="type">GtkListBox</span></a>, and more.</p>
<p>The full, buildable sources for these examples can be found
    in the examples/ directory of the GTK+ source distribution, or
    <a class="ulink" href="https://git.gnome.org/browse/gtk+/tree/examples" target="_top">online</a> in the GTK+ git repository.
    You can build each example separately by using make with the <code class="filename">Makefile.example</code>
    file. For more information, see the <code class="filename">README</code> included in the
    examples directory.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.5"></a>A trivial application</h3></div></div></div>
<p>When using <a class="link" href="GtkApplication.html" title="GtkApplication"><span class="type">GtkApplication</span></a>, the <code class="function">main()</code> function can be very
      simple. We just call <code class="function">g_application_run()</code> and give it an instance
      of our application class.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="cp">#include</span> <span class="cpf">&lt;gtk/gtk.h&gt;</span><span class="cp"></span>

<span class="cp">#include</span> <span class="cpf">&quot;exampleapp.h&quot;</span><span class="cp"></span>

<span class="kt">int</span>
<span class="nf">main</span> <span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
  <span class="k">return</span> <span class="n">g_application_run</span> <span class="p">(</span><span class="n">G_APPLICATION</span> <span class="p">(</span><span class="n">example_app_new</span> <span class="p">()),</span> <span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">);</span>
<span class="p">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>All the application logic is in the application class, which
      is a subclass of <a class="link" href="GtkApplication.html" title="GtkApplication"><span class="type">GtkApplication</span></a>. Our example does not yet have any
      interesting functionality. All it does is open a window when it is
      activated without arguments, and open the files it is given, if it
      is started with arguments.</p>
<p>To handle these two cases, we override the <code class="function">activate()</code> vfunc,
      which gets called when the application is launched without commandline
      arguments, and the <code class="function">open()</code> vfunc, which gets called when the application
      is launched with commandline arguments.</p>
<p>To learn more about GApplication entry points, consult the
      GIO <a class="ulink" href="https://developer.gnome.org/gio/2.36/GApplication.html#GApplication.description" target="_top">documentation</a>.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="cp">#include</span> <span class="cpf">&lt;gtk/gtk.h&gt;</span><span class="cp"></span>

<span class="cp">#include</span> <span class="cpf">&quot;exampleapp.h&quot;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&quot;exampleappwin.h&quot;</span><span class="cp"></span>

<span class="k">struct</span> <span class="nc">_ExampleApp</span>
<span class="p">{</span>
  <span class="n">GtkApplication</span> <span class="n">parent</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">G_DEFINE_TYPE</span><span class="p">(</span><span class="n">ExampleApp</span><span class="p">,</span> <span class="n">example_app</span><span class="p">,</span> <span class="n">GTK_TYPE_APPLICATION</span><span class="p">);</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_init</span> <span class="p">(</span><span class="n">ExampleApp</span> <span class="o">*</span><span class="n">app</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_activate</span> <span class="p">(</span><span class="n">GApplication</span> <span class="o">*</span><span class="n">app</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">ExampleAppWindow</span> <span class="o">*</span><span class="n">win</span><span class="p">;</span>

  <span class="n">win</span> <span class="o">=</span> <span class="n">example_app_window_new</span> <span class="p">(</span><span class="n">EXAMPLE_APP</span> <span class="p">(</span><span class="n">app</span><span class="p">));</span>
  <span class="n">gtk_window_present</span> <span class="p">(</span><span class="n">GTK_WINDOW</span> <span class="p">(</span><span class="n">win</span><span class="p">));</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_open</span> <span class="p">(</span><span class="n">GApplication</span>  <span class="o">*</span><span class="n">app</span><span class="p">,</span>
                  <span class="n">GFile</span>        <span class="o">**</span><span class="n">files</span><span class="p">,</span>
                  <span class="n">gint</span>           <span class="n">n_files</span><span class="p">,</span>
                  <span class="k">const</span> <span class="n">gchar</span>   <span class="o">*</span><span class="n">hint</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">GList</span> <span class="o">*</span><span class="n">windows</span><span class="p">;</span>
  <span class="n">ExampleAppWindow</span> <span class="o">*</span><span class="n">win</span><span class="p">;</span>
  <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>

  <span class="n">windows</span> <span class="o">=</span> <span class="n">gtk_application_get_windows</span> <span class="p">(</span><span class="n">GTK_APPLICATION</span> <span class="p">(</span><span class="n">app</span><span class="p">));</span>
  <span class="k">if</span> <span class="p">(</span><span class="n">windows</span><span class="p">)</span>
    <span class="n">win</span> <span class="o">=</span> <span class="n">EXAMPLE_APP_WINDOW</span> <span class="p">(</span><span class="n">windows</span><span class="o">-&gt;</span><span class="n">data</span><span class="p">);</span>
  <span class="k">else</span>
    <span class="n">win</span> <span class="o">=</span> <span class="n">example_app_window_new</span> <span class="p">(</span><span class="n">EXAMPLE_APP</span> <span class="p">(</span><span class="n">app</span><span class="p">));</span>

  <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">n_files</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
    <span class="n">example_app_window_open</span> <span class="p">(</span><span class="n">win</span><span class="p">,</span> <span class="n">files</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>

  <span class="n">gtk_window_present</span> <span class="p">(</span><span class="n">GTK_WINDOW</span> <span class="p">(</span><span class="n">win</span><span class="p">));</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_class_init</span> <span class="p">(</span><span class="n">ExampleAppClass</span> <span class="o">*</span><span class="n">class</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">G_APPLICATION_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">activate</span> <span class="o">=</span> <span class="n">example_app_activate</span><span class="p">;</span>
  <span class="n">G_APPLICATION_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">open</span> <span class="o">=</span> <span class="n">example_app_open</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">ExampleApp</span> <span class="o">*</span>
<span class="n">example_app_new</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">return</span> <span class="nf">g_object_new</span> <span class="p">(</span><span class="n">EXAMPLE_APP_TYPE</span><span class="p">,</span>
                       <span class="s">&quot;application-id&quot;</span><span class="p">,</span> <span class="s">&quot;org.gtk.exampleapp&quot;</span><span class="p">,</span>
                       <span class="s">&quot;flags&quot;</span><span class="p">,</span> <span class="n">G_APPLICATION_HANDLES_OPEN</span><span class="p">,</span>
                       <span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Another important class that is part of the application support
      in GTK+ is <a class="link" href="GtkApplicationWindow.html" title="GtkApplicationWindow"><span class="type">GtkApplicationWindow</span></a>. It is typically subclassed as well.
      Our subclass does not do anything yet, so we will just get an empty
      window.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="cp">#include</span> <span class="cpf">&lt;gtk/gtk.h&gt;</span><span class="cp"></span>

<span class="cp">#include</span> <span class="cpf">&quot;exampleapp.h&quot;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&quot;exampleappwin.h&quot;</span><span class="cp"></span>

<span class="k">struct</span> <span class="nc">_ExampleAppWindow</span>
<span class="p">{</span>
  <span class="n">GtkApplicationWindow</span> <span class="n">parent</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">G_DEFINE_TYPE</span><span class="p">(</span><span class="n">ExampleAppWindow</span><span class="p">,</span> <span class="n">example_app_window</span><span class="p">,</span> <span class="n">GTK_TYPE_APPLICATION_WINDOW</span><span class="p">);</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_window_init</span> <span class="p">(</span><span class="n">ExampleAppWindow</span> <span class="o">*</span><span class="n">app</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_window_class_init</span> <span class="p">(</span><span class="n">ExampleAppWindowClass</span> <span class="o">*</span><span class="n">class</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">}</span>

<span class="n">ExampleAppWindow</span> <span class="o">*</span>
<span class="n">example_app_window_new</span> <span class="p">(</span><span class="n">ExampleApp</span> <span class="o">*</span><span class="n">app</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">return</span> <span class="nf">g_object_new</span> <span class="p">(</span><span class="n">EXAMPLE_APP_WINDOW_TYPE</span><span class="p">,</span> <span class="s">&quot;application&quot;</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span>
<span class="n">example_app_window_open</span> <span class="p">(</span><span class="n">ExampleAppWindow</span> <span class="o">*</span><span class="n">win</span><span class="p">,</span>
                         <span class="n">GFile</span>            <span class="o">*</span><span class="n">file</span><span class="p">)</span>
<span class="p">{</span>
<span class="p">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>As part of the initial setup of our application, we also
      create an icon and a desktop file.</p>
<div class="informalfigure"><div class="mediaobject"><img src="exampleapp.png"></div></div>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="p">[</span><span class="n">Desktop</span> <span class="n">Entry</span><span class="p">]</span>
<span class="n">Type</span><span class="o">=</span><span class="n">Application</span>
<span class="n">Name</span><span class="o">=</span><span class="n">Example</span>
<span class="n">Icon</span><span class="o">=</span><span class="n">exampleapp</span>
<span class="n">StartupNotify</span><span class="o">=</span><span class="nb">true</span>
<span class="n">Exec</span><span class="o">=</span><span class="err">@</span><span class="n">bindir</span><span class="err">@</span><span class="o">/</span><span class="n">exampleapp</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Note that <em class="replaceable"><code>@bindir@</code></em> needs to be replaced
      with the actual path to the binary before this desktop file can be used.</p>
<p>Here is what we've achieved so far:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app1.png"></div></div>
<p>This does not look very impressive yet, but our application
      is already presenting itself on the session bus, it has single-instance
      semantics, and it accepts files as commandline arguments.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.6"></a>Populating the window</h3></div></div></div>
<p>In this step, we use a <a class="link" href="GtkBuilder.html" title="GtkBuilder"><span class="type">GtkBuilder</span></a> template to associate a
      <a class="link" href="GtkBuilder.html" title="GtkBuilder"><span class="type">GtkBuilder</span></a> ui file with our application window class.</p>
<p>Our simple ui file puts a <a class="link" href="GtkHeaderBar.html" title="GtkHeaderBar"><span class="type">GtkHeaderBar</span></a> on top of a <a class="link" href="GtkStack.html" title="GtkStack"><span class="type">GtkStack</span></a>
      widget. The header bar contains a <a class="link" href="GtkStackSwitcher.html" title="GtkStackSwitcher"><span class="type">GtkStackSwitcher</span></a>, which is a
      standalone widget to show a row of 'tabs' for the pages of a <a class="link" href="GtkStack.html" title="GtkStack"><span class="type">GtkStack</span></a>.
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.8</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">template</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;ExampleAppWindow&quot;</span> <span class="n">parent</span><span class="o">=</span><span class="s">&quot;GtkApplicationWindow&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;title&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">Example</span> <span class="n">Application</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-width&quot;</span><span class="o">&gt;</span><span class="mi">600</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-height&quot;</span><span class="o">&gt;</span><span class="mi">400</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;content_box&quot;</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;orientation&quot;</span><span class="o">&gt;</span><span class="n">vertical</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkHeaderBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;header&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;title&quot;</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStackSwitcher&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;tabs&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span><span class="n">stack</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStack&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">template</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>To make use of this file in our application, we revisit
      our <a class="link" href="GtkApplicationWindow.html" title="GtkApplicationWindow"><span class="type">GtkApplicationWindow</span></a> subclass, and call
      <a class="link" href="GtkWidget.html#gtk-widget-class-set-template-from-resource" title="gtk_widget_class_set_template_from_resource ()"><code class="function">gtk_widget_class_set_template_from_resource()</code></a> from the class init
      function to set the ui file as template for this class. We also
      add a call to <a class="link" href="GtkWidget.html#gtk-widget-init-template" title="gtk_widget_init_template ()"><code class="function">gtk_widget_init_template()</code></a> in the instance init
      function to instantiate the template for each instance of our
      class.</p>
<div class="informalexample">
<pre class="programlisting">
 ...

static void
example_app_window_init (ExampleAppWindow *win)
{
  gtk_widget_init_template (GTK_WIDGET (win));
}

static void
example_app_window_class_init (ExampleAppWindowClass *class)
{
  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
                                               "/org/gtk/exampleapp/window.ui");
}

 ...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application2/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>You may have noticed that we used the <code class="literal">_from_resource()</code> variant
      of the function that sets a template. Now we need to use <a class="ulink" href="https://developer.gnome.org/gio/stable/GResource.html" target="_top">GLib's resource functionality</a>
      to include the ui file in the binary. This is commonly done by listing
      all resources in a .gresource.xml file, such as this:
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">gresources</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">gresource</span> <span class="n">prefix</span><span class="o">=</span><span class="s">&quot;/org/gtk/exampleapp&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">file</span> <span class="n">preprocess</span><span class="o">=</span><span class="s">&quot;xml-stripblanks&quot;</span><span class="o">&gt;</span><span class="n">window</span><span class="p">.</span><span class="n">ui</span><span class="o">&lt;/</span><span class="n">file</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">gresource</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">gresources</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>This file has to be converted into a C source file that will be
      compiled and linked into the application together with the other source
      files. To do so, we use the glib-compile-resources utility:</p>
<pre class="screen">
      glib-compile-resources exampleapp.gresource.xml --target=resources.c --generate-source
      </pre>
<p>Our application now looks like this:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app2.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.7"></a>Opening files</h3></div></div></div>
<p>In this step, we make our application show the content of
      all the files that it is given on the commandline.</p>
<p>To this end, we add a private struct to our application
      window subclass and keep a reference to the <a class="link" href="GtkStack.html" title="GtkStack"><span class="type">GtkStack</span></a> there.
      The <a class="link" href="GtkWidget.html#gtk-widget-class-bind-template-child-private" title="gtk_widget_class_bind_template_child_private()"><code class="function">gtk_widget_class_bind_template_child_private()</code></a> function
      arranges things so that after instantiating the template, the
      <em class="parameter"><code>stack</code></em> member of the private struct will point to the widget of
      the same name from the template.</p>
<div class="informalexample">
<pre class="programlisting">
...

struct _ExampleAppWindowPrivate
{
  GtkWidget *stack;
};

G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);

...

static void
example_app_window_class_init (ExampleAppWindowClass *class)
{
  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
                                               "/org/gtk/exampleapp/window.ui");
  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (class), ExampleAppWindow, stack);
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application3/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>Now we revisit the <code class="function">example_app_window_open()</code> function that
      is called for each commandline argument, and construct a GtkTextView
      that we then add as a page to the stack:</p>
<div class="informalexample">
<pre class="programlisting">
...

void
example_app_window_open (ExampleAppWindow *win,
                         GFile            *file)
{
  ExampleAppWindowPrivate *priv;
  gchar *basename;
  GtkWidget *scrolled, *view;
  gchar *contents;
  gsize length;

  priv = example_app_window_get_instance_private (win);
  basename = g_file_get_basename (file);

  scrolled = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolled);
  gtk_widget_set_hexpand (scrolled, TRUE);
  gtk_widget_set_vexpand (scrolled, TRUE);
  view = gtk_text_view_new ();
  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
  gtk_widget_show (view);
  gtk_container_add (GTK_CONTAINER (scrolled), view);
  gtk_stack_add_titled (GTK_STACK (priv-&gt;stack), scrolled, basename, basename);

  if (g_file_load_contents (file, NULL, &amp;contents, &amp;length, NULL, NULL))
    {
      GtkTextBuffer *buffer;

      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
      gtk_text_buffer_set_text (buffer, contents, length);
      g_free (contents);
    }

  g_free (basename);
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application3/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>Note that we did not have to touch the stack switcher
      at all. It gets all its information from the stack that it
      belongs to. Here, we are passing the label to show for each
      file as the last argument to the <a class="link" href="GtkStack.html#gtk-stack-add-titled" title="gtk_stack_add_titled ()"><code class="function">gtk_stack_add_titled()</code></a>
      function.</p>
<p>Our application is beginning to take shape:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app3.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.8"></a>An application menu</h3></div></div></div>
<p>An application menu is shown by GNOME shell at the top of the
      screen. It is meant to collect infrequently used actions that affect
      the whole application.</p>
<p>Just like the window template, we specify our application menu
      in a ui file, and add it as a resource to our binary.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.0</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">menu</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;appmenu&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">section</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">item</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">_Preferences</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;action&quot;</span><span class="o">&gt;</span><span class="n">app</span><span class="p">.</span><span class="n">preferences</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">section</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">section</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">item</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">_Quit</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;action&quot;</span><span class="o">&gt;</span><span class="n">app</span><span class="p">.</span><span class="n">quit</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">section</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">menu</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>To associate the app menu with the application, we have to call
      <a class="link" href="GtkApplication.html#gtk-application-set-app-menu" title="gtk_application_set_app_menu ()"><code class="function">gtk_application_set_app_menu()</code></a>. Since app menus work by activating
      <span class="type">GActions</span>, we also have to add a suitable set of actions to our
      application.</p>
<p>Both of these tasks are best done in the <code class="function">startup()</code> vfunc,
      which is guaranteed to be called once for each primary application
      instance:</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
preferences_activated (GSimpleAction *action,
                       GVariant      *parameter,
                       gpointer       app)
{
}

static void
quit_activated (GSimpleAction *action,
                GVariant      *parameter,
                gpointer       app)
{
  g_application_quit (G_APPLICATION (app));
}

static GActionEntry app_entries[] =
{
  { "preferences", preferences_activated, NULL, NULL, NULL },
  { "quit", quit_activated, NULL, NULL, NULL }
};

static void
example_app_startup (GApplication *app)
{
  GtkBuilder *builder;
  GMenuModel *app_menu;
  const gchar *quit_accels[2] = { "&lt;Ctrl&gt;Q", NULL };

  G_APPLICATION_CLASS (example_app_parent_class)-&gt;startup (app);

  g_action_map_add_action_entries (G_ACTION_MAP (app),
                                   app_entries, G_N_ELEMENTS (app_entries),
                                   app);
  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
                                         "app.quit",
                                         quit_accels);

  builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
  app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
  gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
  g_object_unref (builder);
}

static void
example_app_class_init (ExampleAppClass *class)
{
  G_APPLICATION_CLASS (class)-&gt;startup = example_app_startup;
  ...
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application4/exampleapp.c" target="_top">full source</a>)</p>
</div>
<p>Our preferences menu item does not do anything yet,
      but the Quit menu item is fully functional. Note that it
      can also be activated by the usual Ctrl-Q shortcut. The
      shortcut was added with <a class="link" href="GtkApplication.html#gtk-application-set-accels-for-action" title="gtk_application_set_accels_for_action ()"><code class="function">gtk_application_set_accels_for_action()</code></a>.
      </p>
<p>The application menu looks like this:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app4.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.9"></a>A preference dialog</h3></div></div></div>
<p>A typical application will have a some preferences that
      should be remembered from one run to the next. Even for our
      simple example application, we may want to change the font
      that is used for the content.</p>
<p>We are going to use GSettings to store our preferences.
      GSettings requires a schema that describes our settings:</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">schemalist</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">schema</span> <span class="n">path</span><span class="o">=</span><span class="s">&quot;/org/gtk/exampleapp/&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;org.gtk.exampleapp&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">key</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;font&quot;</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;s&quot;</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="k">default</span><span class="o">&gt;</span><span class="err">&#39;</span><span class="n">Monospace</span> <span class="mi">12</span><span class="err">&#39;</span><span class="o">&lt;/</span><span class="k">default</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">summary</span><span class="o">&gt;</span><span class="n">Font</span><span class="o">&lt;/</span><span class="n">summary</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">description</span><span class="o">&gt;</span><span class="n">The</span> <span class="n">font</span> <span class="n">to</span> <span class="n">be</span> <span class="n">used</span> <span class="k">for</span> <span class="n">content</span><span class="p">.</span><span class="o">&lt;/</span><span class="n">description</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">key</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">key</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;transition&quot;</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;s&quot;</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">choices</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">choice</span> <span class="n">value</span><span class="o">=</span><span class="err">&#39;</span><span class="n">none</span><span class="err">&#39;</span><span class="o">/&gt;</span>
        <span class="o">&lt;</span><span class="n">choice</span> <span class="n">value</span><span class="o">=</span><span class="err">&#39;</span><span class="n">crossfade</span><span class="err">&#39;</span><span class="o">/&gt;</span>
        <span class="o">&lt;</span><span class="n">choice</span> <span class="n">value</span><span class="o">=</span><span class="err">&#39;</span><span class="n">slide</span><span class="o">-</span><span class="n">left</span><span class="o">-</span><span class="n">right</span><span class="err">&#39;</span><span class="o">/&gt;</span>
      <span class="o">&lt;/</span><span class="n">choices</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="k">default</span><span class="o">&gt;</span><span class="err">&#39;</span><span class="n">none</span><span class="err">&#39;</span><span class="o">&lt;/</span><span class="k">default</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">summary</span><span class="o">&gt;</span><span class="n">Transition</span><span class="o">&lt;/</span><span class="n">summary</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">description</span><span class="o">&gt;</span><span class="n">The</span> <span class="n">transition</span> <span class="n">to</span> <span class="n">use</span> <span class="n">when</span> <span class="n">switching</span> <span class="n">tabs</span><span class="p">.</span><span class="o">&lt;/</span><span class="n">description</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">key</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">schema</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">schemalist</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Before we can make use of this schema in our application,
      we need to compile it into the binary form that GSettings
      expects. GIO provides <a class="ulink" href="https://developer.gnome.org/gio/2.36/ch31s06.html" target="_top">macros</a>
      to do this in autotools-based projects.</p>
<p>Next, we need to connect our settings to the widgets
      that they are supposed to control. One convenient way to do
      this is to use GSettings bind functionality to bind settings
      keys to object properties, as we do here for the transition
      setting.</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
example_app_window_init (ExampleAppWindow *win)
{
  ExampleAppWindowPrivate *priv;

  priv = example_app_window_get_instance_private (win);
  gtk_widget_init_template (GTK_WIDGET (win));
  priv-&gt;settings = g_settings_new ("org.gtk.exampleapp");

  g_settings_bind (priv-&gt;settings, "transition",
                   priv-&gt;stack, "transition-type",
                   G_SETTINGS_BIND_DEFAULT);
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application5/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>The code to connect the font setting is a little more involved,
      since there is no simple object property that it corresponds to, so
      we are not going to go into that here.</p>
<p>At this point, the application will already react if you
      change one of the settings, e.g. using the gsettings commandline
      tool. Of course, we expect the application to provide a preference
      dialog for these. So lets do that now. Our preference dialog will
      be a subclass of GtkDialog, and we'll use the same techniques that
      we've already seen: templates, private structs, settings
      bindings.</p>
<p>Lets start with the template.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.8</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">template</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;ExampleAppPrefs&quot;</span> <span class="n">parent</span><span class="o">=</span><span class="s">&quot;GtkDialog&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;title&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">Preferences</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;resizable&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;modal&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">child</span> <span class="n">internal</span><span class="o">-</span><span class="n">child</span><span class="o">=</span><span class="s">&quot;vbox&quot;</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;vbox&quot;</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkGrid&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;grid&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;margin&quot;</span><span class="o">&gt;</span><span class="mi">6</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;row-spacing&quot;</span><span class="o">&gt;</span><span class="mi">12</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;column-spacing&quot;</span><span class="o">&gt;</span><span class="mi">6</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkLabel&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;fontlabel&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span><span class="o">&gt;</span><span class="nl">_Font</span><span class="p">:</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;use-underline&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;mnemonic-widget&quot;</span><span class="o">&gt;</span><span class="n">font</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;xalign&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;left-attach&quot;</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;top-attach&quot;</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkFontButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;font&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;left-attach&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;top-attach&quot;</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkLabel&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;transitionlabel&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span><span class="o">&gt;</span><span class="nl">_Transition</span><span class="p">:</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;use-underline&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;mnemonic-widget&quot;</span><span class="o">&gt;</span><span class="n">transition</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;xalign&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;left-attach&quot;</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;top-attach&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkComboBoxText&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;transition&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">items</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">item</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;none&quot;</span><span class="o">&gt;</span><span class="n">None</span><span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">item</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;crossfade&quot;</span><span class="o">&gt;</span><span class="n">Fade</span><span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">item</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;slide-left-right&quot;</span><span class="o">&gt;</span><span class="n">Slide</span><span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">items</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;left-attach&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;top-attach&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">template</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Next comes the dialog subclass.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="cp">#include</span> <span class="cpf">&lt;gtk/gtk.h&gt;</span><span class="cp"></span>

<span class="cp">#include</span> <span class="cpf">&quot;exampleapp.h&quot;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&quot;exampleappwin.h&quot;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&quot;exampleappprefs.h&quot;</span><span class="cp"></span>

<span class="k">struct</span> <span class="nc">_ExampleAppPrefs</span>
<span class="p">{</span>
  <span class="n">GtkDialog</span> <span class="n">parent</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">typedef</span> <span class="k">struct</span> <span class="nc">_ExampleAppPrefsPrivate</span> <span class="n">ExampleAppPrefsPrivate</span><span class="p">;</span>

<span class="k">struct</span> <span class="nc">_ExampleAppPrefsPrivate</span>
<span class="p">{</span>
  <span class="n">GSettings</span> <span class="o">*</span><span class="n">settings</span><span class="p">;</span>
  <span class="n">GtkWidget</span> <span class="o">*</span><span class="n">font</span><span class="p">;</span>
  <span class="n">GtkWidget</span> <span class="o">*</span><span class="n">transition</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">G_DEFINE_TYPE_WITH_PRIVATE</span><span class="p">(</span><span class="n">ExampleAppPrefs</span><span class="p">,</span> <span class="n">example_app_prefs</span><span class="p">,</span> <span class="n">GTK_TYPE_DIALOG</span><span class="p">)</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_prefs_init</span> <span class="p">(</span><span class="n">ExampleAppPrefs</span> <span class="o">*</span><span class="n">prefs</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">ExampleAppPrefsPrivate</span> <span class="o">*</span><span class="n">priv</span><span class="p">;</span>

  <span class="n">priv</span> <span class="o">=</span> <span class="n">example_app_prefs_get_instance_private</span> <span class="p">(</span><span class="n">prefs</span><span class="p">);</span>
  <span class="n">gtk_widget_init_template</span> <span class="p">(</span><span class="n">GTK_WIDGET</span> <span class="p">(</span><span class="n">prefs</span><span class="p">));</span>
  <span class="n">priv</span><span class="o">-&gt;</span><span class="n">settings</span> <span class="o">=</span> <span class="n">g_settings_new</span> <span class="p">(</span><span class="s">&quot;org.gtk.exampleapp&quot;</span><span class="p">);</span>

  <span class="n">g_settings_bind</span> <span class="p">(</span><span class="n">priv</span><span class="o">-&gt;</span><span class="n">settings</span><span class="p">,</span> <span class="s">&quot;font&quot;</span><span class="p">,</span>
                   <span class="n">priv</span><span class="o">-&gt;</span><span class="n">font</span><span class="p">,</span> <span class="s">&quot;font&quot;</span><span class="p">,</span>
                   <span class="n">G_SETTINGS_BIND_DEFAULT</span><span class="p">);</span>
  <span class="n">g_settings_bind</span> <span class="p">(</span><span class="n">priv</span><span class="o">-&gt;</span><span class="n">settings</span><span class="p">,</span> <span class="s">&quot;transition&quot;</span><span class="p">,</span>
                   <span class="n">priv</span><span class="o">-&gt;</span><span class="n">transition</span><span class="p">,</span> <span class="s">&quot;active-id&quot;</span><span class="p">,</span>
                   <span class="n">G_SETTINGS_BIND_DEFAULT</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_prefs_dispose</span> <span class="p">(</span><span class="n">GObject</span> <span class="o">*</span><span class="n">object</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">ExampleAppPrefsPrivate</span> <span class="o">*</span><span class="n">priv</span><span class="p">;</span>

  <span class="n">priv</span> <span class="o">=</span> <span class="n">example_app_prefs_get_instance_private</span> <span class="p">(</span><span class="n">EXAMPLE_APP_PREFS</span> <span class="p">(</span><span class="n">object</span><span class="p">));</span>
  <span class="n">g_clear_object</span> <span class="p">(</span><span class="o">&amp;</span><span class="n">priv</span><span class="o">-&gt;</span><span class="n">settings</span><span class="p">);</span>

  <span class="n">G_OBJECT_CLASS</span> <span class="p">(</span><span class="n">example_app_prefs_parent_class</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">dispose</span> <span class="p">(</span><span class="n">object</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kt">void</span>
<span class="n">example_app_prefs_class_init</span> <span class="p">(</span><span class="n">ExampleAppPrefsClass</span> <span class="o">*</span><span class="n">class</span><span class="p">)</span>
<span class="p">{</span>
  <span class="n">G_OBJECT_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">dispose</span> <span class="o">=</span> <span class="n">example_app_prefs_dispose</span><span class="p">;</span>

  <span class="n">gtk_widget_class_set_template_from_resource</span> <span class="p">(</span><span class="n">GTK_WIDGET_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">),</span>
                                               <span class="s">&quot;/org/gtk/exampleapp/prefs.ui&quot;</span><span class="p">);</span>
  <span class="n">gtk_widget_class_bind_template_child_private</span> <span class="p">(</span><span class="n">GTK_WIDGET_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">),</span> <span class="n">ExampleAppPrefs</span><span class="p">,</span> <span class="n">font</span><span class="p">);</span>
  <span class="n">gtk_widget_class_bind_template_child_private</span> <span class="p">(</span><span class="n">GTK_WIDGET_CLASS</span> <span class="p">(</span><span class="n">class</span><span class="p">),</span> <span class="n">ExampleAppPrefs</span><span class="p">,</span> <span class="n">transition</span><span class="p">);</span>
<span class="p">}</span>

<span class="n">ExampleAppPrefs</span> <span class="o">*</span>
<span class="n">example_app_prefs_new</span> <span class="p">(</span><span class="n">ExampleAppWindow</span> <span class="o">*</span><span class="n">win</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">return</span> <span class="nf">g_object_new</span> <span class="p">(</span><span class="n">EXAMPLE_APP_PREFS_TYPE</span><span class="p">,</span> <span class="s">&quot;transient-for&quot;</span><span class="p">,</span> <span class="n">win</span><span class="p">,</span> <span class="s">&quot;use-header-bar&quot;</span><span class="p">,</span> <span class="n">TRUE</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Now we revisit the <code class="literal">preferences_activated()</code> function in our
      application class, and make it open a new preference dialog.</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
preferences_activated (GSimpleAction *action,
                       GVariant      *parameter,
                       gpointer       app)
{
  ExampleAppPrefs *prefs;
  GtkWindow *win;

  win = gtk_application_get_active_window (GTK_APPLICATION (app));
  prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
  gtk_window_present (GTK_WINDOW (prefs));
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application6/exampleapp.c" target="_top">full source</a>)</p>
</div>
<p>After all this work, our application can now show
      a preference dialog like this:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app6.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.10"></a>Adding a search bar</h3></div></div></div>
<p>We continue to flesh out the functionality of our application.
      For now, we add search. GTK+ supports this with <a class="link" href="GtkSearchEntry.html" title="GtkSearchEntry"><span class="type">GtkSearchEntry</span></a> and
      <a class="link" href="GtkSearchBar.html" title="GtkSearchBar"><span class="type">GtkSearchBar</span></a>. The search bar is a widget that can slide in from the
      top to present a search entry.</p>
<p>We add a toggle button to the header bar, which can be used
      to slide out the search bar below the header bar.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.8</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">template</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;ExampleAppWindow&quot;</span> <span class="n">parent</span><span class="o">=</span><span class="s">&quot;GtkApplicationWindow&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;title&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">Example</span> <span class="n">Application</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-width&quot;</span><span class="o">&gt;</span><span class="mi">600</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-height&quot;</span><span class="o">&gt;</span><span class="mi">400</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;content_box&quot;</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;orientation&quot;</span><span class="o">&gt;</span><span class="n">vertical</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkHeaderBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;header&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;title&quot;</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStackSwitcher&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;tabs&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span><span class="n">stack</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkToggleButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;sensitive&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">style</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">class</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;image-button&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkImage&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search-icon&quot;</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-name&quot;</span><span class="o">&gt;</span><span class="n">edit</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="n">symbolic</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-size&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                  <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">end</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchbar&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchEntry&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchentry&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;search-changed&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;search_text_changed&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStack&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;notify::visible-child&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;visible_child_changed&quot;</span><span class="o">/&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">template</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>Implementing the search needs quite a few code changes that
      we are not going to completely go over here. The central piece of
      the search implementation is a signal handler that listens for
      text changes in the search entry.</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
search_text_changed (GtkEntry         *entry,
                     ExampleAppWindow *win)
{
  ExampleAppWindowPrivate *priv;
  const gchar *text;
  GtkWidget *tab;
  GtkWidget *view;
  GtkTextBuffer *buffer;
  GtkTextIter start, match_start, match_end;

  text = gtk_entry_get_text (entry);

  if (text[0] == '\0')
    return;

  priv = example_app_window_get_instance_private (win);

  tab = gtk_stack_get_visible_child (GTK_STACK (priv-&gt;stack));
  view = gtk_bin_get_child (GTK_BIN (tab));
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

  /* Very simple-minded search implementation */
  gtk_text_buffer_get_start_iter (buffer, &amp;start);
  if (gtk_text_iter_forward_search (&amp;start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
                                    &amp;match_start, &amp;match_end, NULL))
    {
      gtk_text_buffer_select_range (buffer, &amp;match_start, &amp;match_end);
      gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &amp;match_start,
                                    0.0, FALSE, 0.0, 0.0);
    }
}

static void
example_app_window_init (ExampleAppWindow *win)
{

...

  gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), search_text_changed);

...

}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application7/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>With the search bar, our application now looks like this:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app7.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.11"></a>Adding a side bar</h3></div></div></div>
<p>As another piece of functionality, we are adding a sidebar,
      which demonstrates <a class="link" href="GtkMenuButton.html" title="GtkMenuButton"><span class="type">GtkMenuButton</span></a>, <a class="link" href="GtkRevealer.html" title="GtkRevealer"><span class="type">GtkRevealer</span></a> and <a class="link" href="GtkListBox.html" title="GtkListBox"><span class="type">GtkListBox</span></a>.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.8</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">template</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;ExampleAppWindow&quot;</span> <span class="n">parent</span><span class="o">=</span><span class="s">&quot;GtkApplicationWindow&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;title&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">Example</span> <span class="n">Application</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-width&quot;</span><span class="o">&gt;</span><span class="mi">600</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-height&quot;</span><span class="o">&gt;</span><span class="mi">400</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;content_box&quot;</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;orientation&quot;</span><span class="o">&gt;</span><span class="n">vertical</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkHeaderBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;header&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;title&quot;</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStackSwitcher&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;tabs&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span><span class="n">stack</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkToggleButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;sensitive&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">style</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">class</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;image-button&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkImage&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search-icon&quot;</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-name&quot;</span><span class="o">&gt;</span><span class="n">edit</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="n">symbolic</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-size&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                  <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">end</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkMenuButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;gears&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;direction&quot;</span><span class="o">&gt;</span><span class="n">none</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;use-popover&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">style</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">class</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;image-button&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">end</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchbar&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchEntry&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchentry&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;search-changed&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;search_text_changed&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;hbox&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkRevealer&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;sidebar&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;transition-type&quot;</span><span class="o">&gt;</span><span class="n">slide</span><span class="o">-</span><span class="n">right</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                 <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkScrolledWindow&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;sidebar-sw&quot;</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;hscrollbar-policy&quot;</span><span class="o">&gt;</span><span class="n">never</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;vscrollbar-policy&quot;</span><span class="o">&gt;</span><span class="n">automatic</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                     <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkListBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;words&quot;</span><span class="o">&gt;</span>
                       <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                       <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;selection-mode&quot;</span><span class="o">&gt;</span><span class="n">none</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                     <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                   <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
                 <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStack&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;notify::visible-child&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;visible_child_changed&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">template</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>The code to populate the sidebar with buttons for the words
      found in each file is a little too involved to go into here. But we'll
      look at the code to add the gears menu.</p>
<p>As expected by now, the gears menu is specified in a GtkBuilder
      ui file.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.0</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">menu</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;menu&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">section</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">item</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">_Words</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;action&quot;</span><span class="o">&gt;</span><span class="n">win</span><span class="p">.</span><span class="n">show</span><span class="o">-</span><span class="n">words</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">section</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">menu</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>To connect the menuitem to the show-words setting, we use
      a <span class="type">GAction</span> corresponding to the given <span class="type">GSettings</span> key.</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
example_app_window_init (ExampleAppWindow *win)
{

...

  builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
  menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv-&gt;gears), menu);
  g_object_unref (builder);

  action = g_settings_create_action (priv-&gt;settings, "show-words");
  g_action_map_add_action (G_ACTION_MAP (win), action);
  g_object_unref (action);
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application8/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>What our application looks like now:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app8.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.12"></a>Properties</h3></div></div></div>
<p>Widgets and other objects have many useful properties.</p>
<p>Here we show some ways to use them in new and flexible ways,
      by wrapping them in actions with <span class="type">GPropertyAction</span> or by binding them
      with <span class="type">GBinding</span>.</p>
<p>To set this up, we add two labels to the header bar in our
      window template, named <em class="parameter"><code>lines_label</code></em> and <em class="parameter"><code>lines</code></em>, and bind them to
      struct members in the private struct, as we've seen a couple of times
      by now.</p>
<p>We add a new "Lines" menu item to the gears menu, which
      triggers the show-lines action:</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.0</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">menu</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;menu&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">section</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">item</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">_Words</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;action&quot;</span><span class="o">&gt;</span><span class="n">win</span><span class="p">.</span><span class="n">show</span><span class="o">-</span><span class="n">words</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">item</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">_Lines</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">attribute</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;action&quot;</span><span class="o">&gt;</span><span class="n">win</span><span class="p">.</span><span class="n">show</span><span class="o">-</span><span class="n">lines</span><span class="o">&lt;/</span><span class="n">attribute</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">item</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">section</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">menu</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>To make this menu item do something, we create a property
      action for the visible property of the <em class="parameter"><code>lines</code></em> label, and add it to the
      actions of the window. The effect of this is that the visibility
      of the label gets toggled every time the action is activated.</p>
<p>Since we want both labels to appear and disappear together,
      we bind the visible property of the <em class="parameter"><code>lines_label</code></em> widget to the
      same property of the <em class="parameter"><code>lines</code></em> widget.</p>
<div class="informalexample">
<pre class="programlisting">
...

static void
example_app_window_init (ExampleAppWindow *win)
{
  ...

  action = (GAction*) g_property_action_new ("show-lines", priv-&gt;lines, "visible");
  g_action_map_add_action (G_ACTION_MAP (win), action);
  g_object_unref (action);

  g_object_bind_property (priv-&gt;lines, "visible",
                          priv-&gt;lines_label, "visible",
                          G_BINDING_DEFAULT);
}

...
        </pre>
<p>(<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application9/exampleappwin.c" target="_top">full source</a>)</p>
</div>
<p>We also need a function that counts the lines of the currently
      active tab, and updates the <em class="parameter"><code>lines</code></em> label. See the
      <a class="ulink" href="https://gitlab.gnome.org/GNOME/gtk/blob/gtk-3-22/examples/application9/exampleappwin.c" target="_top">full source</a>
      if you are interested in the details.</p>
<p>This brings our example application to this appearance:</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app9.png"></div></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.2.3.12.13"></a>Header bar</h3></div></div></div>
<p>Our application already uses a GtkHeaderBar, but so far it
      still gets a 'normal' window titlebar on top of that. This is a
      bit redundant, and we will now tell GTK+ to use the header bar
      as replacement for the titlebar. To do so, we move it around to
      be a direct child of the window, and set its type to be titlebar.</p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="o">&lt;?</span><span class="n">xml</span> <span class="n">version</span><span class="o">=</span><span class="s">&quot;1.0&quot;</span> <span class="n">encoding</span><span class="o">=</span><span class="s">&quot;UTF-8&quot;</span><span class="o">?&gt;</span>
<span class="o">&lt;</span><span class="n">interface</span><span class="o">&gt;</span>
  <span class="o">&lt;!--</span> <span class="n">interface</span><span class="o">-</span><span class="n">requires</span> <span class="n">gtk</span><span class="o">+</span> <span class="mf">3.8</span> <span class="o">--&gt;</span>
  <span class="o">&lt;</span><span class="n">template</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;ExampleAppWindow&quot;</span> <span class="n">parent</span><span class="o">=</span><span class="s">&quot;GtkApplicationWindow&quot;</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;title&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="n">Example</span> <span class="n">Application</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-width&quot;</span><span class="o">&gt;</span><span class="mi">600</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;default-height&quot;</span><span class="o">&gt;</span><span class="mi">400</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;titlebar&quot;</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkHeaderBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;header&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;show-close-button&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkLabel&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;lines_label&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;label&quot;</span> <span class="n">translatable</span><span class="o">=</span><span class="s">&quot;yes&quot;</span><span class="o">&gt;</span><span class="nl">Lines</span><span class="p">:</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">start</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkLabel&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;lines&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">start</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span> <span class="n">type</span><span class="o">=</span><span class="s">&quot;title&quot;</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStackSwitcher&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;tabs&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span><span class="n">stack</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkToggleButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;sensitive&quot;</span><span class="o">&gt;</span><span class="n">False</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">style</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">class</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;image-button&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkImage&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;search-icon&quot;</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-name&quot;</span><span class="o">&gt;</span><span class="n">edit</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="n">symbolic</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                    <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;icon-size&quot;</span><span class="o">&gt;</span><span class="mi">1</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                  <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">end</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkMenuButton&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;gears&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;direction&quot;</span><span class="o">&gt;</span><span class="n">none</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;use-popover&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">style</span><span class="o">&gt;</span>
                  <span class="o">&lt;</span><span class="n">class</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;image-button&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">packing</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;pack-type&quot;</span><span class="o">&gt;</span><span class="n">end</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">packing</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
    <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;content_box&quot;</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;orientation&quot;</span><span class="o">&gt;</span><span class="n">vertical</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchBar&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchbar&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkSearchEntry&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;searchentry&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;search-changed&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;search_text_changed&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;hbox&quot;</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkRevealer&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;sidebar&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;transition-type&quot;</span><span class="o">&gt;</span><span class="n">slide</span><span class="o">-</span><span class="n">right</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                 <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkScrolledWindow&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;sidebar-sw&quot;</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;hscrollbar-policy&quot;</span><span class="o">&gt;</span><span class="n">never</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;vscrollbar-policy&quot;</span><span class="o">&gt;</span><span class="n">automatic</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                   <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
                     <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkListBox&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;words&quot;</span><span class="o">&gt;</span>
                       <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                       <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;selection-mode&quot;</span><span class="o">&gt;</span><span class="n">none</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
                     <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                   <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
                 <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
                <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="n">child</span><span class="o">&gt;</span>
              <span class="o">&lt;</span><span class="n">object</span> <span class="n">class</span><span class="o">=</span><span class="s">&quot;GtkStack&quot;</span> <span class="n">id</span><span class="o">=</span><span class="s">&quot;stack&quot;</span><span class="o">&gt;</span>
                <span class="o">&lt;</span><span class="n">signal</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;notify::visible-child&quot;</span> <span class="n">handler</span><span class="o">=</span><span class="s">&quot;visible_child_changed&quot;</span><span class="o">/&gt;</span>
                <span class="o">&lt;</span><span class="n">property</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;visible&quot;</span><span class="o">&gt;</span><span class="n">True</span><span class="o">&lt;/</span><span class="n">property</span><span class="o">&gt;</span>
              <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
            <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
          <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
        <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
      <span class="o">&lt;/</span><span class="n">object</span><span class="o">&gt;</span>
    <span class="o">&lt;/</span><span class="n">child</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">template</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">interface</span><span class="o">&gt;</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>A small extra bonus of using a header bar is that we get
      a fallback application menu for free. Here is how the
      application now looks, if this fallback is used.</p>
<div class="informalfigure"><div class="mediaobject"><img src="getting-started-app10.png"></div></div>
<p>If we set up the window icon for our window, the menu button
      will use that instead of the generic placeholder icon you see
      here.</p>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>